<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script type="text/javascript" src="../JS/vue.js"></script>
</head>

<body>
  <div id="root">
    <h2>今天天气</h2>
    <button @click="changeWeather">切换天气{{info}}</button>
    <hr />
    <h2>hot值为{{numbers.hot}}</h2>
    <button @click="numbers.hot++">点我加1</button>
    <h2>cold值为{{numbers.cold}}</h2>
    <button @click="numbers.cold++">点我加1</button>
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false
  new Vue({
    el: '#root',
    data: {
      isHot: true,
      numbers: {
        hot: 35,
        cold: 10
      }
    },
    computed: {
      info() {
        return this.isHot ? '炎热' : '寒冷'
      }
    },
    methods: {
      changeWeather() {
        this.isHot = !this.isHot
      }
    },
    watch: {
      isHot(newValue, oldValue) {
        console.log(newValue, oldValue)
      },
      // 监视多级结构中所有的属性的变化
      numbers: {
        deep: true,
        handler() {
          console.log('变了')
        }
      }
    }
  })
</script>

</html>